package Dispatcher;

import HallCallStrategy.EasyHallCallStrategy;
import HallCallStrategy.HallCallStrategy;

/**
 * Receives the floor number and direction from the dispatcher and prints it out
 * 
 * @author Varun Maryada, Sanat Dixit, Steve Tannahill
 * 
 */
public class SendHallCallRequestThread extends Thread {
	private int floor;
	private int dir;
	private GroupDispatcher gd;

	public SendHallCallRequestThread(int floorNumber, int direction,
			GroupDispatcher gd) {
		this.gd = gd;
		this.floor = floorNumber;
		this.dir = direction;
	}

	@Override
	public void run() {
		String strDirection = (this.dir == 1) ? "UP" : "DOWN";
		System.out.println("Received request from Floor " + this.floor
				+ "to go " + strDirection);
		HallCallStrategy hc = new EasyHallCallStrategy();
		int bestElevatorIndex = hc.getBestElevator(this.floor,
				this.dir, gd.status);
		
		//error check - got bad elevator id, so print error message and exit
		if (bestElevatorIndex == -1) {
			System.out.println("Could not find an elevator");
			return;
		}
		
		System.out.println("Sending destination to elavator " + bestElevatorIndex
								+ "'s list");
		if (gd.elevators.size() > 0) {
			gd.elevators.get(bestElevatorIndex).println(
					"Floor: " + floor + ", Direction: " + dir);
		}
	}
}